package com.spikything.ui {
	
	import com.spikything.ui.IconButton;
	import flash.display.DisplayObject;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.events.MouseEvent;
	import com.spikything.gfx.Scale9Bitmap;
	import com.spikything.gfx.TextLabel;

	public class StateButton extends IconButton {
		
		protected static 	const 	ACTIVE_COLOUR 	:Number 		= 0xff0000;
		protected static 	const 	INACTIVE_COLOUR :Number 		= 0x999999;
		private 			var 	_selected 		:Boolean;
		private 			var 	activeIcon 		:DisplayObject;
		
		public function StateButton (icons:String = "", x:Number = 0, y:Number = 0, label:String="") {
			super(icons, x, y, label);
			selected = false;
		}
		
		override protected function setup (icons:String, label:String):void {
			super.setup(icons.split("|")[0], label);
			activeIcon = addChild(new this[icons.split("|")[1]]() as Bitmap);
			activeIcon.x = defaultIcon.x;
			activeIcon.y = defaultIcon.y;
		}
		
		public function set selected (value:Boolean):void {
			_selected = value;
			activeIcon.visible = _selected;
			defaultIcon.visible = !_selected;
			_labelField.textColor = _selected ? ACTIVE_COLOUR : INACTIVE_COLOUR;
		}
		
		public function get selected ():Boolean {
			return _selected;
		}
		
	}
	
}